package com.example.pcl.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.pcl.pojo.entity.StudentFeedback;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 学生评价表，记录学生对心理咨询师的评价 Mapper 接口
 * </p>
 *
 * @author xx
 * @since 2024-12-17
 */
@Mapper
public interface StudentFeedbackMapper extends BaseMapper<StudentFeedback> {

    // 计算总体好评率
    @Select("SELECT SUM(IF(rating >= 4, 1, 0)) / COUNT(rating) * 100 AS overall_rating " +
            "FROM student_feedback WHERE rating IS NOT NULL")
    double calculateOverallRating();


    // 获取咨询师的好评率数据
    List<Map<String, Object>> getConsultantRatingData();

    @Select("SELECT COUNT(*) AS totalReviews, SUM(IF(rating >= 4, 1, 0)) AS goodReviews FROM student_feedback WHERE counselor_id = #{counselorId}")
    Map<String, Object> getReviewStatsByCounselorId(Integer counselorId);
}
